下载
1 2 3 4 5 6 7
| [root@localhost ~] [root@localhost src] [root@localhost src] ncurses ncurses-devel libtool-ltdl-devel* make bison bison-devel libaio [root@localhost src] [root@localhost src] [root@localhost haproxy-1.4.25]
|
开始编译安装
MAKE 参数参考文件中的 README 文件
1 2 3 4 5 6 7 8 9 10 11
| [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] [root@localhost haproxy-1.4.25] > install -m 644 doc/$x.txt /usr/local/doc/haproxy ; \ > done [root@localhost haproxy-1.4.25]
|
安装完成,检测是否安装成功
1 2 3
| [root@localhost haproxy-1.4.25] HA-Proxy version 1.4.25 2014/03/27 Copyright 2000-2014 Willy Tarreau <w@1wt.eu>
|
则安装成功
配置 haproxy.cfg 文件
用的 /root/haproxy-1.4.25/examples/haproxy.cfg 这个是自带的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| [root@localhost examples] global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 chroot /usr/local/haproxy uid 99 gid 99 daemon defaults log global mode http option httplog option dontlognull retries 3 maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen web_proxy bind *:80 mode http option httpchk GET /index.html server s1 192.168.11.210:80 weight 3 check server s2 192.168.11.211:80 weight 3 check
|
启动服务
1 2 3
| [root@localhost examples] [WARNING] 316/220055 (2376) : parsing [/root/haproxy-1.4.25/examples/haproxy.cfg:22]: keyword 'redispatch' is deprecated, please use 'option redispatch' instead. [ALERT] 316/220055 (2376) : [haproxy.main()] Cannot chroot(/usr/local/sbin/haproxy).
|
出现的报错信息,下面我们来解决问题。因为上面配置文件是我改后的,应该没有什么问题。
[ALERT] 316/220055 (2376) : [haproxy.main()] Cannot chroot(/usr/local/sbin/haproxy).
是配置文件chroot的目录不对,根据我的文档安装改成 chroot /urs/local/haproxy 就可以解决了
执行 mkdir /usr/share/haproxy
[WARNING] 316/220055 (2376) : parsing [/root/haproxy-1.4.25/examples/haproxy.cfg:22]: keyword 'redispatch' is deprecated, please use 'option redispatch' instead.
这个报错信息是配置文件22行的问题, 我是做了注释掉就可以起动服务了。 注释到相对应的错误行
再次起动服务:
1 2
| [root@localhost examples] [root@localhost examples]
|
没有任何提示,那我们检测一下是否启动成功
看一下进程信息
1 2 3
| [root@localhost examples] nobody 3826 1 0 22:38 ? 00:00:00 haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfg root 3837 1260 0 22:38 pts/0 00:00:00 grep haproxy
|
进程已经在
看一下端口信息
1 2 3
| [root@localhost examples] tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3826/haproxy udp 0 0 0.0.0.0:43549 0.0.0.0:* 3826/haproxy
|
把配置文件移动到/etc目录下
1 2
| [root@localhost examples] [root@localhost etc]
|
复制haproxy配置文件到/etc/目录下面
再一次查看进程 kill掉。 在用/etc/haproxy.cfg的配置文件启动看看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [root@localhost etc] nobody 3826 1 0 22:38 ? 00:00:00 haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfg root 3901 1260 0 22:40 pts/0 00:00:00 grep haproxy [root@localhost etc] [root@localhost etc] root 3928 1260 0 22:41 pts/0 00:00:00 grep haproxy ``` & ```bash [root@localhost etc] [root@localhost etc] nobody 3959 1 0 22:42 ? 00:00:00 haproxy -f /etc/haproxy.cfg root 3965 1260 0 22:43 pts/0 00:00:00 grep haproxy.cfg
|
已经看到运行成功
设置以服务形式启动
目录切换到/etc/init.d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| [root@localhost etc] [root@localhost init.d] #!/bin/bash . /etc/rc.d/init.d/functions . /etc/sysconfig/network [ "$NETWORKING" = "no" ] && exit 0 config="/etc/haproxy.cfg" exec="/usr/local/haproxy/sbin/haproxy" prog=$(basename $exec) [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog lockfile=/var/lock/subsys/haproxy check() { $exec -c -V -f $config } start() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi echo -n $"Starting $prog: " daemon $exec -D -f $config -p /var/run/$prog.pid retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi stop start } reload() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi echo -n $"Reloading $prog: " $exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid) retval=$? echo return $retval } force_reload() { restart } fdr_status() { status $prog } case "$1" in start|stop|restart|reload) $1 ;; force-reload) force_reload ;; checkconfig) check ;; status) fdr_status ;; condrestart|try-restart) [ ! -f $lockfile ] || restart ;; *) echo $"Usage: $0 {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}" exit 2 esac
|
重起服务haproxy
1 2
| [root@localhost init.d] env: /etc/init.d/haproxy: Permission denied
|
这个提示。大概是权限问题。下面加上执行权限
1 2 3 4 5
| [root@localhost init.d] -rw-r--r--. 1 root root 2588 Nov 13 23:02 haproxy [root@localhost init.d] [root@localhost init.d] -rw-r-xr-x. 1 root root 2588 Nov 13 23:02 haproxy
|
看一下进程是否存在,不存在重起haproxy服务
[root@localhost init.d]
root 7409 1260 0 23:56 pts/0 00:00:00 grep haproxy
[root@localhost init.d]
Stopping haproxy: [FAILED]
Starting haproxy: [ OK ]
[root@localhost init.d]
nobody 7444 1 0 23:56 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -D -f /etc/haproxy.cfg -p /var/run/haproxy.pid
root 7449 1260 0 23:56 pts/0 00:00:00 grep haproxy
[root@localhost init.d]
配置上面就完成了